import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// import eslint from 'vite-plugin-eslint'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import path from 'path'
import postCssPxToRem from 'postcss-pxtorem'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const root = process.cwd()
  const env = loadEnv(mode, root)
  return {
    plugins: [
      vue(),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/svg')],
        symbolId: 'icon-[dir]-[name]',
      }),
      // eslint(),
      AutoImport({
        resolvers: [ElementPlusResolver(
          // {
          //   // 自动引入修改主题色添加这一行，使用预处理样式，不添加将会导致使用ElMessage，ElNotification等组件时默认的主题色会覆盖自定义的主题色
          //   importStyle: 'sass',
          // }
        )],
      }),
      Components({
        resolvers: [ElementPlusResolver(
          {
            // 自动引入修改主题色添加这一行，使用预处理样式
            importStyle: 'sass',
          }
        )]
      }),
    ],
    server: {
      port: 9001,
      proxy: {
        '/redis': {
          // target: 'http://10.254.2.113:8001/',
          target: 'http://127.0.0.1:8000/',
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, '')
        },
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          // 自定义的主题色
          additionalData: '@use "@/styles/element.scss" as *;',
        },
      },
      
    },
    resolve: {
      alias: [
        {
          find: '@/',
          replacement: path.resolve(__dirname, 'src') + '/',
        }
      ]
    }
  }
})
